
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>

<%@page import="com.tss.util.*"%>
<%@page import="com.jedi.*"%>
<%@page import="com.store.*"%>
<%@page import="java.io.File"%>
<%@page import="java.util.*"%>
<%@page import="java.text.*"%>
<%@include file="../global_var.jsp"%>
<%@include file="../check_login.jsp"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
User just_user = (User)session.getAttribute("LoginUser");

boolean blModiAll = false;
boolean blModiMySelf = false;
boolean blIsMyArticle = false;



ArticleMgr articleMgr = new ArticleMgr();
String strErr = "";
String cmd = ParamUtils.getParameter(request,"cmd","");
String article_id = ParamUtils.getParameter(request,"article_id","");
Article article = articleMgr.get(article_id);
if (article == null || article.getId().trim().equals(""))  strErr = "该文章不存在!";

if (just_user.hasPower("10804")) blModiMySelf = true;
if (just_user.hasPower("10805")) blModiAll = true;
if (strErr.trim().equals("") && just_user.getId().equals(article.getAuthorId())) blIsMyArticle = true;

String parent_id = "";
if (strErr.trim().equals("")) parent_id = article.getCategory().getParentId();
String article_title   = "";
String article_content = "";
String doc_info        = "";

if (!cmd.trim().equals("")) {
	article_title   = ParamUtils.getParameter(request,"article_title","");
	article_content = ParamUtils.getParameter(request,"article_content","");
	doc_info        = ParamUtils.getParameter(request,"doc_info","");
}

if (cmd.trim().equals("modify") && strErr.trim().equals("")) {
	article.setArticleTitle(article_title);
	article.setArticleContent(article_content);
	article.setDocInfo(doc_info);
	//article.setDocInfo(doc_info);
	if (strErr.trim().equals("") && !(
		blModiAll || (blIsMyArticle && blModiMySelf))
		) {
		strErr = "对不起，您没有此权限!";
	}
	if (strErr.trim().equals("") && article_title.trim().equals("")) {
		strErr = "文章标题不能为空!";
	}
	if (strErr.trim().equals("") && article_content.trim().equals("")) {
		strErr = "文章内容不能为空!";
	}
	if (strErr.trim().equals("") && article_content.length() >= 800) {
		strErr = "文章内容不能超过800字符!";
	}
	if (strErr.trim().equals("")) {
		article.update();
		if (article.hasErr()) strErr = article.getErrHtml();
	}
}

if (cmd.trim().equals("delete") && strErr.trim().equals("")) {
	String savePath = "upload/knowledge/article" + "/" + article.getDocInfo();
	if (strErr.trim().equals("") && !(
		blModiAll || (blIsMyArticle && blModiMySelf))
		) {
		strErr = "对不起，您没有此权限!";
	}
	if (strErr.trim().equals("")) {
		try {
			File myFile = new File(pageContext.getServletContext().getRealPath(savePath));
			myFile.delete();
		}
		catch(Exception ex) {
			ex.printStackTrace();
		}
		article.delete();
		if (article.hasErr()) strErr = article.getErrHtml();
	}
}

if (cmd.trim().equals("") && strErr.trim().equals("")) {
	article_title = article.getArticleTitle();
	article_content = article.getArticleContent();
	doc_info = article.getDocInfo();
}
%>
<html>
<head>
   <base href="<%=basePath%>">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title></title>
<link href="style/main.css" rel="stylesheet" type="text/css">
<script language="javascript" src="js/common.js"></script>
<script language="javascript">
function clk_modify_submit() {
	var oForm = document.operatorForm;
	if (oForm.article_title.value == "") {
		alert("文章标题不能为空!");
		oForm.article_title.focus();
		return false;
	}
	if (oForm.article_content.value == "") {
		alert("文章内容不能为空!");
		oForm.article_content.focus();
		return false;
	}
	oForm.cmd.value = "modify";
	oForm.submit();
}

function clk_delete_submit() {
	var oForm = document.operatorForm;
	oForm.cmd.value = "delete";
	oForm.submit();
}

function upload_file() {
	var oForm = document.operatorForm;
	var r = window.showModalDialog('../selectFrm.htm','knowledge_mgt/upload_article.jsp','dialogHeight: 200px;dialogWidth: 300px; center: yes; status:no;help: no');
	if(r && r != "") {
		oForm.doc_info.value = r;
	}
}

</script>
</head>
<body 
	leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
	<tr>
		<td style="padding-left:25px;">
		<form name="operatorForm" method="post">
		<table width="100%" border="0" cellspacing="0" cellpadding="0">
			<tr>
				<td height="31" valign="top" background="images/title_bk_01.gif"
					style="padding-left:10px;padding-top:6px;">
				<table width="100%" border="0" cellspacing="0" cellpadding="0">
					<tr>
						<td width="50%" style="color:#FFFFFF;font-size:13px;"><b>知识库</b>
						-&gt; <b>文章修改</b></td>
						<td width="50%" align="right" style="padding-right:10px;">&nbsp; <span
							onclick="right_menu_clk('know_article_list.jsp?parent_id=<%=parent_id%>');"
							style="cursor:hand;color:#FFFFFF;font-size:12px;text-de--ation: underline;">文章列表</span>
						</td>
					</tr>
				</table>
				</td>
			</tr>
			<tr>
				<td height="100" align="center" valign="top"
					style="padding-top:20px;padding-bottom:10px;">
				<table width="80%" border="0" cellpadding="3" cellspacing="1"
					bgcolor="#FFFFFF">
					<%if (!strErr.trim().equals("")) {%>
					<tr>
						<td width="30%" height="28" align="right" bgcolor="#858585"><font
							color="#FFFFFF">错误提示：</font></td>
						<td bgcolor="#EDEDF0"><font color=red><%=strErr%></font>&nbsp;</td>
					</tr>
					<%}%>
					<%
              if (article != null && !article.getId().equals("")) {
              	String content = article.getArticleContent();
              	content = content.replaceAll("\n","<br>");
              %>
					<tr>
						<td width="30%" height="24" align="right" bgcolor="#858585"><font
							color="#FFFFFF">文章标题：</font></td>
						<td bgcolor="#D7D7DB"><input name="article_title" type="text"
							class="inputbox" value="<%=article_title%>" size="30"
							maxlength="50"></td>
					</tr>
					<tr>
						<td height="24" align="right" bgcolor="#858585"><font
							color="#FFFFFF">文章内容：</font></td>
						<td bgcolor="#EDEDF0"><textarea name="article_content" cols="40"
							rows="5"><%=article_content%></textarea></td>
					</tr>
					<!--
					<tr>
						<td height="24" align="right" bgcolor="#858585"><font
							color="#FFFFFF">文档附件：</font></td>
						<td bgcolor="#EDEDF0"><input type="text" name="doc_info"
							value="<%=doc_info%>" size="30" maxlength="50"> &nbsp; <input
							type="button" value="上传附件" class="inputButton"
							onclick="upload_file();"></td>
					</tr>
					//-->
					<tr>
						<td height="24" align="right" bgcolor="#858585"><font
							color="#FFFFFF">文档附件：</font></td>
						<td bgcolor="#D7D7DB">
						
							
							   <input type="text" name="doc_info" value="<%=doc_info%>" size="30" maxlength="50"> &nbsp; 
                  <input type="button" value="上传附件" class="inputButton" onclick="upload_file();"> 
                  </td>
					</tr>
					<tr>
						<td height="24" align="right" bgcolor="#858585"><font
							color="#FFFFFF">文章作者：</font></td>
						<td bgcolor="#D7D7DB"><%=article.getAuthorName()%></td>
					</tr>
					<tr>
						<td height="24" align="right" bgcolor="#858585"><font
							color="#FFFFFF">所属分类：</font></td>
						<td bgcolor="#D7D7DB"><%=article.getCategory().getCategoryName()%></td>
					</tr>
					<tr>
						<td height="24" align="right" bgcolor="#858585"><font
							color="#FFFFFF">发布时间：</font></td>
						<td bgcolor="#D7D7DB"><%=article.getIssueTime()%></td>
					</tr>
					<tr>
						<td height="24" align="right" bgcolor="#858585"><font
							color="#FFFFFF">人气指数：</font></td>
						<td bgcolor="#D7D7DB"><%=article.getHit()%></td>
					</tr>
					<tr>
						<td height="24" align="right" bgcolor="#EDEDF0">&nbsp;</td>
						<td bgcolor="#EDEDF0"><input type="button"
							onclick="clk_modify_submit();" name="btn" value="修 改"
							class="inputButton"> <input type="button"
							onclick="clk_delete_submit();" name="btn" value="删 除"
							class="inputButton"> <input type="reset" name="reset" value="重 写"
							class="inputButton"> <input type="hidden" name="cmd" value=""></td>
					</tr>
				
					<%}%>
				</table>
				</td>
			</tr>
		</table>
			</form>
		</td>
	</tr>
</table>
<%if (cmd.equals("modify") && strErr.trim().equals("")){%>
<script language="javascript">
alert("记录信息修改成功!");
location.href = "know_article_list.jsp?parent_id=<%=parent_id%>";
</script>
<%}%>
<%if (cmd.trim().equals("delete") && strErr.trim().equals("")) {%>
<script language="javascript">
alert("记录信息删除成功!");
location.href = "know_article_list.jsp?parent_id=<%=parent_id%>";
</script>
<%}%>
</body>
</html>
